package com.dd.cloud.user.service.plat.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dd.cloud.common.config.common.ProfilesProperties;
import com.dd.cloud.common.constants.ConsultConstants;
import com.dd.cloud.common.constants.TemplateConstants;
import com.dd.cloud.common.constants.ZekeConstants;
import com.dd.cloud.common.utils.BigDecimalUtils;
import com.dd.cloud.common.utils.DateUtils;
import com.dd.cloud.common.vo.LoginInfo;
import com.dd.cloud.user.config.WechatPatientAppletConfig;
import com.dd.cloud.user.entity.consult.ConsultSubscribe;
import com.dd.cloud.user.entity.doctor.DoctorDetail;
import com.dd.cloud.user.entity.order.OrderPay;
import com.dd.cloud.user.entity.plat.PlatformLogin;
import com.dd.cloud.user.entity.plat.PlatformWechatInfo;
import com.dd.cloud.user.entity.pres.PresPrescription;
import com.dd.cloud.user.mq.MQConfig;
import com.dd.cloud.user.mq.RabbitSend;
import com.dd.cloud.user.req.template.TemplateData;
import com.dd.cloud.user.req.template.TemplateMessageGzhReq;
import com.dd.cloud.user.req.template.TemplateMessageReq;
import com.dd.cloud.user.service.consule.IConsultSubscribeService;
import com.dd.cloud.user.service.doctor.IDoctorDetailService;
import com.dd.cloud.user.service.news.INewsInfoService;
import com.dd.cloud.user.service.order.IOrderPayService;
import com.dd.cloud.user.service.patient.IPatientMedRankService;
import com.dd.cloud.user.service.plat.IPlatformLoginService;
import com.dd.cloud.user.service.plat.IPlatformWechatInfoService;
import com.dd.cloud.user.service.plat.TemplateMessAgeService;
import com.dd.cloud.user.service.pres.IPresPrescriptionService;
import com.zk.pay.constants.CS;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
@Slf4j
public class TemplateMessAgeServiceImp implements TemplateMessAgeService {
    @Autowired
    private IOrderPayService orderPayService;
    @Autowired
    private IConsultSubscribeService consultSubscribeService;
    @Autowired
    private IPlatformLoginService platformLoginService;
    @Autowired
    private IDoctorDetailService doctorDetailService;
    @Autowired
    private WechatPatientAppletConfig wechatPatientAppletConfig;
    @Autowired
    private ProfilesProperties profilesProperties;
    @Autowired
    private IPlatformWechatInfoService platformWechatInfoService;
    @Autowired
    private IPatientMedRankService patientMedRankService;
    @Autowired
    private IPresPrescriptionService presPrescriptionService;
    @Autowired
    private RabbitSend rabbitSend;
    @Autowired
    private INewsInfoService newsInfoService;

    @Override
    public void sendConsultTemplateMessage(String orderNo) {
        log.info("发送问诊预约成功模板消息");
        OrderPay orderPay = orderPayService.getOrderPay(orderNo);
        if (orderPay == null) {
            return;
        }
        ConsultSubscribe consultSubscribe = consultSubscribeService.getById(orderPay.getServerNo());
        if (consultSubscribe == null) {
            return;
        }
        String openId = getUserOpenId(consultSubscribe.getPatientId());
        if (StringUtils.isBlank(openId)) {
            return;
        }
        sendMessage(consultSubscribe, openId, "预约成功", "您已预约成功,请留意医生接诊信息");
    }

    public void sendMessage(ConsultSubscribe consultSubscribe, String openId, String status, String message) {
        String path = "pages/inquiryList/inquiryList";
        String day = DateUtils.dateToString(consultSubscribe.getDay());
        Map<String, TemplateData> map = new HashMap<>();
        map.put("thing4", new TemplateData(consultSubscribe.getPatientName()));
        map.put("thing2", new TemplateData(consultSubscribe.getAim()));
        map.put("time5", new TemplateData(day));
        map.put("phrase3", new TemplateData(status));
        map.put("thing6", new TemplateData(message));
        TemplateMessageReq templateMessageReq = new TemplateMessageReq();
        templateMessageReq.setToUser(openId);
        templateMessageReq.setTemplateId(TemplateConstants.TemplateType.NINE_TEMPLATE_ID);
        templateMessageReq.setPage(path);
        templateMessageReq.setData(map);
        templateMessageReq.setMiniprogramState(getProfiles());
        platformWechatInfoService.sendTemplateMessage(templateMessageReq, platformLoginService.getPatientUserAccessToken());
    }


    //发送退款模板消息 暂未使用
    @Override
    public void sendPresRefundTemplateMessage(String orderNo) {
        log.info("订单号为:{}", orderNo);
        OrderPay orderPay = getOrderPayByOrderNo(orderNo);
        if (orderPay == null) {
            return;
        }
        PresPrescription presPrescription = getPresByTencode(orderPay.getTencode());
        if (presPrescription == null) {
            return;
        }
        ConsultSubscribe consultSubscribe = consultSubscribeService.getById(presPrescription.getConsultId());
        if (consultSubscribe == null) {
            return;
        }
        String openId = getUserOpenId(consultSubscribe.getPatientId());
        if (StringUtils.isBlank(openId)) {
            return;
        }
        String doctorName = getDoctorName(consultSubscribe.getDoctorId());
        String path = "pages/recipeDetail/recipeDetail?tencode=" + presPrescription.getTencode();
        Map<String, TemplateData> map = new HashMap<>();
        map.put("character_string1", new TemplateData(orderNo));
        map.put("thing9", new TemplateData(consultSubscribe.getPatientName()));
        map.put("thing4", new TemplateData(doctorName));
        map.put("amount6", new TemplateData(BigDecimalUtils.divide(orderPay.getTotalFee(), 100) + "元"));
        map.put("thing5", new TemplateData("温馨提醒,您有一笔预约订单已退款成功，订单号:" + orderNo + ",退款金额为" + BigDecimalUtils.divide(orderPay.getTotalFee(), 100) + "元,退款金额已原路退回,请注意查收。"));
        TemplateMessageReq templateMessageReq = new TemplateMessageReq();
        templateMessageReq.setToUser(openId);
        templateMessageReq.setTemplateId(TemplateConstants.TemplateType.THREE_TEMPLATE_ID);
        templateMessageReq.setPage(path);
        templateMessageReq.setData(map);
        templateMessageReq.setMiniprogramState(getProfiles());
        platformWechatInfoService.sendTemplateMessage(templateMessageReq, platformLoginService.getPatientUserAccessToken());
    }

    @Override
    public void sendTreatTemplateMessage(Integer consultId) {
        ConsultSubscribe consultSubscribe = consultSubscribeService.getById(consultId);
        if (consultSubscribe == null) {
            return;
        }
        String openId = getUserOpenId(consultSubscribe.getPatientId());
        if (StringUtils.isBlank(openId)) {
            return;
        }
        sendMessage(consultSubscribe, openId, "已接诊", "您预约的医生已接诊，请及时回复医生信息");
//        保留以防改成公众号发送
//        String doctorName = getDoctorName(consultSubscribe.getDoctorId());
//        String path = "pages/inquiryDetail/inquiryDetail?id=" + consultSubscribe.getId();
//        String day = DateUtils.dateToString(consultSubscribe.getDay());
//        Map<String, TemplateData> map = new HashMap<>();
//        map.put("name1", new TemplateData(consultSubscribe.getPatientName()));
//        map.put("thing8", new TemplateData(type));
//        map.put("name2", new TemplateData(doctorName));
//        map.put("time5", new TemplateData(day));
//        map.put("thing3", new TemplateData("请您注意查看医生发送的问诊消息。若错过就诊时间预约不可取消，医生接诊也后不可取消。"));
//        TemplateMessageReq templateMessageReq = new TemplateMessageReq();
//        templateMessageReq.setToUser(openId);
//        templateMessageReq.setTemplateId(TemplateConstants.TemplateType.EIGHT_TEMPLATE_ID);
//        templateMessageReq.setPage(path);
//        templateMessageReq.setData(map);
//        templateMessageReq.setMiniprogramState(getProfiles());
//        platformWechatInfoService.sendTemplateMessage(templateMessageReq, platformLoginService.getPatientUserAccessToken());
    }


    @Override
    public void sendTemplateMessage() {
        log.info("~开始给患者发送问诊提醒~");
        LambdaQueryWrapper<ConsultSubscribe> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ConsultSubscribe::getStatus, ConsultConstants.Status.SUBMIT).eq(ConsultSubscribe::getDay, LocalDate.now().plusDays(1));
        List<ConsultSubscribe> consultSubscribes = consultSubscribeService.list(wrapper);
        if (CollectionUtils.isNotEmpty(consultSubscribes)) {
            consultSubscribes.stream().forEach(item -> {
                sendTreatTemplateMessage(item.getId());
                newsInfoService.sendTreatMessage(item.getId());
            });
        }
        log.info("~发送患者问诊提醒结束~");
    }


    /**
     * 订单待支付
     *
     * @param orderNo
     */
    @Override
    public void sendOrderNotPayTemplateMessage(String orderNo, String time) {
        OrderPay orderPay = getOrderPayByOrderNo(orderNo);
        if (orderPay == null) {
            return;
        }
        String single = orderPay.getProduct();
        if (!CS.NOTICE_CHANNEL.SINGLE.equals(single)) {
            return;
        }
        ConsultSubscribe consultSubscribe = consultSubscribeService.getById(orderNo);
        if (consultSubscribe == null) {
            return;
        }
        if (consultSubscribe.getStatus() == ConsultConstants.Status.NOPAY) {
            String openId = getUserOpenId(consultSubscribe.getPatientId());
            if (StringUtils.isBlank(openId)) {
                return;
            }
            String path = "pages/appointmentDetail/appointmentDetail?id=" + consultSubscribe.getId();
            Map<String, TemplateData> map = new HashMap<>();
            map.put("character_string9", new TemplateData(orderNo));
            map.put("name1", new TemplateData(consultSubscribe.getPatientName()));
            map.put("thing2", new TemplateData("问诊缴费"));
            map.put("amount3", new TemplateData(BigDecimalUtils.divide(orderPay.getTotalFee(), 100) + "元"));
            map.put("thing4", new TemplateData("为了便于就诊,请您在" + time + "内支付本订单"));
            TemplateMessageReq templateMessageReq = new TemplateMessageReq();
            templateMessageReq.setToUser(openId);
            templateMessageReq.setTemplateId(TemplateConstants.TemplateType.SIX_TEMPLATE_ID);
            templateMessageReq.setPage(path);
            templateMessageReq.setData(map);
            templateMessageReq.setMiniprogramState(getProfiles());
            platformWechatInfoService.sendTemplateMessage(templateMessageReq, platformLoginService.getPatientUserAccessToken());
        }
    }

    @Override
    public void sendPresOrderNotPayTemplateMessage(String orderNo, String time) {
        OrderPay orderPay = getOrderPayByOrderNo(orderNo);
        if (orderPay == null) {
            return;
        }
        String pre = orderPay.getProduct();
        if (!CS.NOTICE_CHANNEL.PRE.equals(pre)) {
            return;
        }
        PresPrescription presPrescription = getPresByTencode(orderPay.getTencode());
        if (presPrescription == null) {
            return;
        }
        ConsultSubscribe consultSubscribe = consultSubscribeService.getById(presPrescription.getConsultId());
        if (consultSubscribe == null) {
            return;
        }
        if (consultSubscribe.getStatus() == ConsultConstants.Status.NOPAY) {
            String openId = getUserOpenId(consultSubscribe.getPatientId());
            if (StringUtils.isBlank(openId)) {
                return;
            }
            String path = "pages/payOrder/payOrder?tencode=" + presPrescription.getTencode();
            Map<String, TemplateData> map = new HashMap<>();
            map.put("character_string9", new TemplateData(orderNo));
            map.put("name1", new TemplateData(consultSubscribe.getPatientName()));
            map.put("thing2", new TemplateData("处方缴费"));
            map.put("amount3", new TemplateData(BigDecimalUtils.divide(orderPay.getTotalFee(), 100) + "元"));
            map.put("thing4", new TemplateData("为了便于就诊,请您在" + time + "内支付本订单"));
            TemplateMessageReq templateMessageReq = new TemplateMessageReq();
            templateMessageReq.setToUser(openId);
            templateMessageReq.setTemplateId(TemplateConstants.TemplateType.SIX_TEMPLATE_ID);
            templateMessageReq.setPage(path);
            templateMessageReq.setData(map);
            templateMessageReq.setMiniprogramState(getProfiles());
            platformWechatInfoService.sendTemplateMessage(templateMessageReq, platformLoginService.getPatientUserAccessToken());
        }
    }

    @Override
    public void sendEvaluateTemplateMessage(String consultId) {
        ConsultSubscribe consultSubscribe = consultSubscribeService.getById(consultId);
        if (consultSubscribe == null) {
            return;
        }
        if (consultSubscribe.getStatus() != ConsultConstants.Status.SUCC) {
            return;
        }
        String openId = getUserOpenId(consultSubscribe.getPatientId());
        if (StringUtils.isBlank(openId)) {
            return;
        }
        sendMessage(consultSubscribe, openId, "已完成", "您的问诊已完成，快去给医生评价吧");
//        String doctorName = getDoctorName(consultSubscribe.getDoctorId());
//        String path = "pages/inquiryDetail/inquiryDetail?id=" + consultSubscribe.getId();
//        String endTime = DateUtils.dateTimeToString(consultSubscribe.getEndDate());
//        Map<String, TemplateData> map = new HashMap<>();
//        map.put("thing5", new TemplateData(consultSubscribe.getPatientName()));
//        map.put("thing9", new TemplateData(doctorName));
//        map.put("thing7", new TemplateData(type));
//        map.put("time2", new TemplateData(endTime));
//        map.put("thing4", new TemplateData("请您对医生服务做出评价"));
//        TemplateMessageReq templateMessageReq = new TemplateMessageReq();
//        templateMessageReq.setToUser(openId);
//        templateMessageReq.setTemplateId(TemplateConstants.TemplateType.FIVE_TEMPLATE_ID);
//        templateMessageReq.setPage(path);
//        templateMessageReq.setData(map);
//        templateMessageReq.setMiniprogramState(getProfiles());
//        platformWechatInfoService.sendTemplateMessage(templateMessageReq, platformLoginService.getPatientUserAccessToken());
    }

    @Override
    public void sendPreSuccessBuyTemplateMessage(String orderNo) {
        OrderPay orderPay = getOrderPayByOrderNo(orderNo);
        if (orderPay == null) {
            return;
        }
        String pre = orderPay.getProduct();
        if (!CS.NOTICE_CHANNEL.PRE.equals(pre)) {
            return;
        }
        PresPrescription presPrescription = getPresByTencode(orderPay.getServerNo());
        if (presPrescription == null) {
            return;
        }
        if (presPrescription.getConsultId() == null || presPrescription.getConsultId() == 0) {
            return;
        }
        ConsultSubscribe consultSubscribe = consultSubscribeService.getById(presPrescription.getConsultId());
        if (consultSubscribe == null) {
            return;
        }
        String openId = getUserOpenId(consultSubscribe.getPatientId());
        if (StringUtils.isBlank(openId)) {
            return;
        }
        String path = "pages/recipeDetail/recipeDetail?tencode=" + presPrescription.getTencode();
        Map<String, TemplateData> map = new HashMap<>();
        map.put("character_string1", new TemplateData(presPrescription.getMedId()));
        map.put("thing2", new TemplateData(consultSubscribe.getPatientName()));
        map.put("amount4", new TemplateData(BigDecimalUtils.divide(orderPay.getTotalFee(), 100) + "元"));
        map.put("character_string7", new TemplateData(orderPay.getOrderNo()));
        map.put("ting5", new TemplateData("尊敬的用户，您的处方订单已完成支付"));
        TemplateMessageReq templateMessageReq = new TemplateMessageReq();
        templateMessageReq.setToUser(openId);
        templateMessageReq.setTemplateId(TemplateConstants.TemplateType.SEVEN_TEMPLATE_ID);
        templateMessageReq.setPage(path);
        templateMessageReq.setData(map);
        templateMessageReq.setMiniprogramState(getProfiles());
        platformWechatInfoService.sendTemplateMessage(templateMessageReq, platformLoginService.getPatientUserAccessToken());
    }


    @Override
    public void sendConsultRefundOrder(String orderNo) {
        log.info("订单号为:{}", orderNo);
        OrderPay orderPay = getOrderPayByOrderNo(orderNo);
        if (orderPay == null) {
            return;
        }
        String product = orderPay.getProduct();
        if (!CS.NOTICE_CHANNEL.SINGLE.equals(product)) {
            return;
        }
        ConsultSubscribe consultSubscribe = consultSubscribeService.getById(orderPay.getServerNo());
        if (consultSubscribe == null) {
            return;
        }
        String openId = getUserOpenId(consultSubscribe.getPatientId());
        if (StringUtils.isBlank(openId)) {
            return;
        }
        sendMessage(consultSubscribe, openId, "已取消", "您的预约项目已取消，退款金额将按原支付账号返还");
//        String doctorName = getDoctorName(consultSubscribe.getDoctorId());
//        String path = "pages/inquiryDetail/inquiryDetail?id=" + consultSubscribe.getId();
//        Map<String, TemplateData> map = new HashMap<>();
//        map.put("character_string1", new TemplateData(orderNo));
//        map.put("thing9", new TemplateData(consultSubscribe.getPatientName()));
//        map.put("thing4", new TemplateData(doctorName));
//        map.put("amount6", new TemplateData(BigDecimalUtils.divide(orderPay.getTotalFee(), 100) + "元"));
//        map.put("thing5", new TemplateData("温馨提醒,您有一笔预约订单已退款成功，订单号:" + orderNo +
//                ",退款金额为" + BigDecimalUtils.divide(orderPay.getTotalFee(), 100) + "元,退款金额已原路退回,请注意查收。"));
//        TemplateMessageReq templateMessageReq = new TemplateMessageReq();
//        templateMessageReq.setToUser(openId);
//        templateMessageReq.setTemplateId(TemplateConstants.TemplateType.THREE_TEMPLATE_ID);
//        templateMessageReq.setPage(path);
//        templateMessageReq.setData(map);
//        templateMessageReq.setMiniprogramState(getProfiles());
//        platformWechatInfoService.sendTemplateMessage(templateMessageReq, platformLoginService.getPatientUserAccessToken());
    }

    @Override
    public void sendRabbitConsultRefundOrder(String orderNo) {
        String param = TemplateConstants.TemplateType.TWELVE_TYPE + "-" + orderNo;
        log.info("问诊订单退款发送,参数为:{}", param);
        rabbitSend.sendMessage(MQConfig.TEMPLATE_EXCHANGE, MQConfig.TEMPLATE_QUEUE, param);
    }

    @Override
    public void sendCancelConsultTemplateMessage(String orderNo) {
        log.info("订单号为:{}", orderNo);
        OrderPay orderPay = getOrderPayByOrderNo(orderNo);
        if (orderPay == null) {
            return;
        }
        String product = orderPay.getProduct();
        if (!CS.NOTICE_CHANNEL.SINGLE.equals(product)) {
            return;
        }
        ConsultSubscribe consultSubscribe = consultSubscribeService.getById(orderPay.getServerNo());
        if (consultSubscribe == null) {
            return;
        }
        String openId = getUserOpenId(consultSubscribe.getPatientId());
        if (StringUtils.isBlank(openId)) {
            return;
        }
        String type = "";
        if (consultSubscribe.getType() == 1) {
            type = "图文问诊";
        } else if (consultSubscribe.getType() == 2) {
            type = "图文咨询";
        }
        String day = DateUtils.dateToString(consultSubscribe.getDay());
        String doctorName = getDoctorName(consultSubscribe.getDoctorId());
        String path = "pages/inquiryDetail/inquiryDetail?id=" + consultSubscribe.getId();
        Map<String, TemplateData> map = new HashMap<>();
        map.put("thing5", new TemplateData(consultSubscribe.getPatientName()));
        map.put("thing7", new TemplateData(doctorName));
        map.put("thing11", new TemplateData(type));
        map.put("time14", new TemplateData(day));
        map.put("thing10", new TemplateData("您的线上预约订单取消成功"));
        TemplateMessageReq templateMessageReq = new TemplateMessageReq();
        templateMessageReq.setToUser(openId);
        templateMessageReq.setTemplateId(TemplateConstants.TemplateType.FOUR_TEMPLATE_ID);
        templateMessageReq.setPage(path);
        templateMessageReq.setData(map);
        templateMessageReq.setMiniprogramState(getProfiles());
        platformWechatInfoService.sendTemplateMessage(templateMessageReq, platformLoginService.getPatientUserAccessToken());
    }

    /**
     * 发送患者公众号待支付订单模板消息
     *
     * @param docName
     * @param patName
     * @param createDate
     * @param amount
     * @param tencode
     */
    @Override
    public void sendPresOrderUnPayTemplateMessage(String docName, String patName, String medId, String createDate, Integer amount, String tencode) {
        Map<String, TemplateData> map = new HashMap<>();
        map.put("thing3", new TemplateData(docName));
        map.put("thing2", new TemplateData(patName));
        map.put("time4", new TemplateData(createDate));
        map.put("amount1", new TemplateData(BigDecimalUtils.divide(amount, 100).toString()));
        List<Integer> patientIds = patientMedRankService.queryPatientIdListByMedId(medId);
        for (Integer patientId : patientIds) {
            String openId = getUserOpenId(getUserOpenId(patientId));
            if (StringUtils.isBlank(openId)) {
                continue;
            }
            TemplateMessageGzhReq templateMessageGzhReq = new TemplateMessageGzhReq();
            templateMessageGzhReq.setToUser(openId);
            templateMessageGzhReq.setTemplateId(TemplateConstants.TemplateType.PRES_ORDER_UN_PAY_PAT_GZH_ID);
            templateMessageGzhReq.setData(map);
            if (Objects.equals(profilesProperties.getActive(), ZekeConstants.ProfilesType.PROD)) {
                templateMessageGzhReq.setUrl("https://admin.dadaotcm.com/dadaomob/pages/guide/init?publicType=1&tencode=" + tencode);
            } else {
                templateMessageGzhReq.setUrl("https://admin.dadaotcm.com/dadaomos/pages/guide/init?publicType=1&tencode=" + tencode);
            }
            platformWechatInfoService.sendTemplateMessageGzh(templateMessageGzhReq, platformLoginService.getPatientUserGzhAccessToken());
        }
    }

    private String getProfiles() {
        if (ZekeConstants.ProfilesType.DEV.equals(profilesProperties.getActive()) || ZekeConstants.ProfilesType.TEST.equals(profilesProperties.getActive())) {
            return "trial";
        }
        return "formal";
    }


    private String getDoctorName(Integer doctorId) {
        LambdaQueryWrapper<DoctorDetail> doctorWrapper = new LambdaQueryWrapper<>();
        doctorWrapper.eq(DoctorDetail::getDoctorId, doctorId);
        DoctorDetail doctorDetail = doctorDetailService.getOne(doctorWrapper);
        String doctorName = "";
        if (doctorDetail != null) {
            doctorName = doctorDetail.getName();
        }
        return doctorName;
    }

    private PresPrescription getPresByTencode(String tencode) {
        LambdaQueryWrapper<PresPrescription> presQueryWrapper = new LambdaQueryWrapper<>();
        presQueryWrapper.eq(PresPrescription::getTencode, tencode);
        PresPrescription presPrescription = presPrescriptionService.getOne(presQueryWrapper);
        return presPrescription;
    }

    private OrderPay getOrderPayByOrderNo(String orderNo) {
        LambdaQueryWrapper<OrderPay> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(OrderPay::getOrderNo, orderNo);
        OrderPay orderPay = orderPayService.getOne(wrapper);
        return orderPay;
    }


    public String getUserOpenId(Integer userId) {
        LambdaQueryWrapper<PlatformLogin> plWrapper = new LambdaQueryWrapper<>();
        plWrapper.eq(PlatformLogin::getUserId, userId).eq(PlatformLogin::getUserType, LoginInfo.UserType.PATIENT);
        PlatformLogin platformLogin = platformLoginService.getOne(plWrapper);
        if (platformLogin != null) {
            return platformLogin.getPlatId();
        }
        return "";
    }

    public String getUserOpenId(String platId) {
        LambdaQueryWrapper<PlatformWechatInfo> qw = new LambdaQueryWrapper<>();
        qw.eq(PlatformWechatInfo::getUnionid, platId);
        PlatformWechatInfo platformWechatInfo = platformWechatInfoService.getOne(qw);
        if (platformWechatInfo != null) {
            return platformWechatInfo.getOpenid();
        }
        return "";
    }
}
